SpeechRecognitionでGoogle Cloud Speech-to-Text APIを使う
https://github.com/Uberi/speech_recognition/blob/master/README.rst で案内される https://cloud.google.com/speech/
SpeechRecognitonドキュメントでの記載はCloud Speech
2022/01時点では Cloud Speech-to-Text と呼ばれている(呼称が変わった)
https://cloud.google.com/speech-to-text/docs/before-you-begin を元に初期設定
Google Cloud プロジェクトの設定
プロジェクトを作る
プロジェクトでSpeech-to-Text APIを有効にする
(1つの請求先アカウントで紐付けられるプロジェクトの上限に達していたため、クオータの引き上げを申請した)
サービス アカウントを作成する
ロールの割当
Cloud Speech-to-Text client(うろ覚え)を設定して絞った
サービス アカウントに JSON キーを作成する
ダウンロードしておく
SpeechRecognitionの依存の指定が不十分
ドキュメントでは google-cloud-speechのインストールを案内
https://github.com/Uberi/speech_recognition#google-cloud-speech-library-for-python-for-google-cloud-speech-api-users
追加でoauth2clientが必要
ModuleNotFoundError: No module named 'oauth2client'
oauth2client should be listed as a requirement for Google Cloud Speech (#555)
https://github.com/Uberi/speech_recognition/issues/368#issuecomment-431350796
google-api-python-clientも必要(こちらを入れればoauth2clientは入る?)
ModuleNotFoundError: No module named 'googleapiclient'
(https://github.com/Uberi/speech_recognition/issues/428)
https://github.com/googleapis/google-api-python-client/
GoogleのAPIを使うのに必要なサービスアカウントを環境変数で管理する
SpeechRecognitionの場合、サービスアカウントはJSON形式の文字列としてメソッド(後述)に渡す
メソッドはrecognizer.recognize_google_cloud
https://github.com/Uberi/speech_recognition/blob/master/reference/library-reference.rst#recognizer_instancerecognize_google_cloudaudio_data-audiodata-credentials_json-unionstr-none--none-language-str--en-us-preferred_phrases-unioniterablestr-none--none-show_all-bool--false---unionstr-dictstr-any
language引数で言語の指定
language="ja-JP"
https://cloud.google.com/speech-to-text/docs/languages